package com.leostadyn.stackfarm.timestatistics.presenter;

import com.leostadyn.stackfarm.timestatistics.model.bean.LoginBean;
import com.leostadyn.stackfarm.timestatistics.model.mentity.LoginModel;
import com.leostadyn.stackfarm.timestatistics.model.minterface.ILoginModel;
import com.leostadyn.stackfarm.timestatistics.view.vinterface.ILoginView;

import io.reactivex.disposables.CompositeDisposable;

public class LoginPresenter extends BasePresenter<ILoginView> {
    public void Judge(String account, String password, CompositeDisposable compositeDisposable) {
        if (!isViewAttached()){
            return;
        }
        mView = getView();
        mView.showWaiting();

        LoginModel.judge(account, password, compositeDisposable, new ILoginModel() {
            @Override
            public void onSuccess(LoginBean loginBean) {
                if (isViewAttached()) {
                    mView.successMessage(loginBean);
                }
            }

            @Override
            public void onSuccess() {

            }

            @Override
            public void onFailure(String s) {
                if (isViewAttached()) {
                    mView.failureMessage(s);
                }
            }

            @Override
            public void noInternet() {
                if (isViewAttached()) {
                    mView.disconnected();
                }
            }

            @Override
            public void onCompleted() {
                if (isViewAttached()){
                    mView.dismissWaiting();
                }
            }

            @Override
            public void onFailure() {

            }

        });
    }
}
